package cn.niit.edu.mobile.studyDemo.apis;

import cn.niit.edu.mobile.studyDemo.dto.HeroInfo;
import cn.niit.edu.mobile.studyDemo.dto.HeroTypeData;
import cn.niit.edu.mobile.studyDemo.dto.SkinInfo;
import cn.niit.edu.mobile.studyDemo.service.HeroService;
import com.mysql.cj.x.protobuf.MysqlxDatatypes;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class HeroApi {
    private final HeroService heroService;
    public HeroApi(@Qualifier("HeroService") HeroService heroService) {
        this.heroService = heroService;
    }

    @ApiOperation("创建一个新皮肤")
    @PostMapping("/skin-infos")
    public ResponseEntity createSkin(@RequestBody SkinInfo skinInfo){
        SkinInfo result = this.heroService.createSkin(skinInfo);
        return ResponseEntity.ok(result);
    }

    /**
     *更新指定英雄次要类型
     * @param id 英雄id
     * @param newTypeId 新的次要类型
     * @return
     */
    @PutMapping("/hero-infos/type2")
    public ResponseEntity updateHeroType(@RequestParam Integer id,@RequestParam Integer newTypeId){
        HeroInfo result = this.heroService.updateHeroType(id,newTypeId);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("统计各类型英雄数量，按类型id升序排列")
    @GetMapping("/hero-infos/type-count")
    public ResponseEntity getTypeCount(){
        List<HeroTypeData> result = this.heroService.getTypeCount();
        return ResponseEntity.ok(result);
    }

    @ApiOperation("按分类名称查询英雄列表，分页返回")
    @GetMapping("/hero-infos/hero-type")
    public ResponseEntity getTypeName(@RequestParam String typeName,@RequestParam Integer page,@RequestParam Integer size){
        Page<HeroInfo> result = this.heroService.getTypeName(typeName, page, size);
        return ResponseEntity.ok(result);
    }
    @ApiOperation("随机获取一个英雄队伍")

    @GetMapping("/hero-infos/team")
    public ResponseEntity getHeroTeam(){
        /*创建一个英雄列表*/
        List<HeroInfo> result = new ArrayList<>();

       HeroInfo result1 = this.heroService.getHeroTeam();
        HeroInfo result2 = this.heroService.getMage();
        HeroInfo result3 = this.heroService.getStriker();
        HeroInfo result4 = this.heroService.getAuxiliary();
        HeroInfo result5 = this.heroService.getAssassin();

        result.add(result1);
        result.add(result2);
        result.add(result3);
        result.add(result4);
        result.add(result5);

        return ResponseEntity.ok(result);

    }

}
